package View;

import home.Config;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;


public class Menu extends JPanel implements ActionListener{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 5237335232850181080L;
	
	private JButton home = new JButton(Clio.createImageIcon("images/button1.png"));
	private JButton ricerca = new JButton(Clio.createImageIcon("images/button2.png"));
	private JButton info = new JButton(Clio.createImageIcon("images/button3.png"));
	private JButton profilo = new JButton(Clio.createImageIcon("images/button4.png"));
	
	public Menu(){
		
		super(new GridBagLayout());
		
		home.addActionListener(this);
		ricerca.addActionListener(this);
		info.addActionListener(this);
		profilo.addActionListener(this);
	
		GridBagConstraints con = new GridBagConstraints();
		
		this.setButton(home,"");
		con.fill = GridBagConstraints.BOTH;
		con.weightx = 0.7;
		con.weighty = 0.7;
		con.gridx = 0;
		con.gridy = 0;
		this.add(home,con);
		
		this.setButton(ricerca, "<HTML>Ricerca<br>Avanzata</HTML>");
		con.fill = GridBagConstraints.BOTH;
		con.weightx = 0.7;
		con.weighty = 0.7;
		con.gridx = 1;
		con.gridy = 0;
		this.add(ricerca,con);
		
		this.setButton(info, "info");
		con.fill = GridBagConstraints.BOTH;
		con.weightx = 0.7;
		con.weighty = 0.7;
		con.gridx = 2;
		con.gridy = 0;
		this.add(info,con);
		
		this.setButton(profilo, "Profilo");
		con.fill = GridBagConstraints.BOTH;
		con.weightx = 0.7;
		con.weighty = 0.7;
		con.gridx = 3;
		con.gridy = 0;
		this.add(profilo,con);
		
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		
		if (e.getSource().equals(home)){
			
			Home home = new Home();
			
			//this.home.setEnabled(false);	
			Clio.AggiornaGUI(home, "home");
			
		}else{
			if (e.getSource().equals(ricerca)){
				
				RicercaAvanzata ric = new RicercaAvanzata();	
				Clio.AggiornaGUI(ric , "ricercaAvanzata");
				
			}else{
				if (e.getSource().equals(info)){
					
					String id = Clio.getFrame().getContentPane().getComponents()[1].getName();
					Info info = new Info(id);
					info.mostraInfo();
					
				}else{
						
						Profilo profilo = new Profilo();		
				        Clio.AggiornaGUI(profilo, "profilo");
						
					}
			}
		}
	}

	
	private JButton setButton (JButton b, String testo){
		b.setLayout(new GridLayout(1,2));
		b.setBackground(Config.getConfig().getCaramello());
		b.setMinimumSize(new Dimension(240,120));
		b.setPreferredSize(new Dimension(240,120));
		b.setFont(Config.getConfig().getFont().deriveFont((float)20));
		b.setForeground(Color.white);
		b.setText(testo);
		b.setFocusPainted(false);
		b.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED,new Color(165,64,66),new Color(204,108,110),null,new Color(108,55,56)));
		return b;
		
	}


}
